import com.H1023.pojo.Pager;
import com.H1023.pojo.Type;
import com.H1023.service.TypeService;
import com.alibaba.fastjson.JSON;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @author MJ
 * @date 2021/9/21 14:53
 */
public class test1 {

    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    TypeService typeServiceImpl = context.getBean("typeServiceImpl", TypeService.class);


    @Test
    public void getAllType(){
        System.out.println(typeServiceImpl.getAllType());
    }

    @Test
    public void a(){
        Type type = typeServiceImpl.getTypeById(1);
        System.out.println(type);
    }
    @Test
    public void updateAllBookType(){
        int typeId=1;
        String typeName="量子书籍";
        int i = typeServiceImpl.updateType(typeId,typeName);
        System.out.println(i);
        a();

    }



    @Test
    public void findByPager(){
        System.out.println(typeServiceImpl.findByPager("total", "desc", 1, 2).getRows());
    }

    @Test
    public void addType(){
        int a = typeServiceImpl.addType(new Type("11书籍", 0));
        System.out.println("this is "+a);
    }

    @Test
    public void fresh(){
        Pager<Type> byPager = typeServiceImpl.findByPager(4, 3);
        System.out.println(byPager.getRows());
    }

    @Test
    public void json(){
        Pager<Type> p = new Pager<Type>();
        p.setTotal(1);
        p.setPage(2);
        p.setSize(3);
        List<Type> list = new ArrayList<Type>();
        list.add(new Type(1,"bbb",1));
        list.add(new Type(2,"bbb",2));
        list.add(new Type(3,"bb3",3));
        p.setRows(list);
        System.out.println(JSON.toJSONString(list));
    }

    @Test
    public void deleteType(){
        int id = 15;
        int i = typeServiceImpl.deleteType(id);
        System.out.println(i);
    }

    @Test
    public void editType(){
        System.out.println(typeServiceImpl.getTypeById(1));
        int id = 1;
        String name = "cnm";
        typeServiceImpl.updateType(id,name);
        System.out.println(typeServiceImpl.getTypeById(1));
    }

}
